<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@include file="common/header.jsp" %>
<div class="clearfix"></div>
<div class="row">
    <div class="col-md-12 col-sm-12 col-xs-12">
        <div class="x_panel">
            <div class="x_title">
                <h2>修改APP最新版本信息 <i class="fa fa-user"></i><small>${devUserSession.devName}</small></h2>
                <div class="clearfix"></div>
            </div>
            <div class="x_title">
                <h2>历史版本列表</h2>
                <div class="clearfix"></div>
            </div>
            <div class="x_content1">
                <div class="clearfix"></div>
                <p class="text-muted font-13 m-b-30"></p>
                <div id="datatable-responsive_wrapper"
                     class="dataTables_wrapper form-inline dt-bootstrap no-footer">
                    <div class="row">
                        <div class="col-sm-12">
                            <table id="datatable-responsive"
                                   class="table table-striped table-bordered dt-responsive nowrap dataTable no-footer dtr-inline collapsed"
                                   cellspacing="0" width="100%" role="grid" aria-describedby="datatable-responsive_info"
                                   style="width: 100%;">
                                <thead>
                                <tr role="row">
                                    <th class="sorting_asc" tabindex="0"
                                        aria-controls="datatable-responsive" rowspan="1" colspan="1"
                                        style="width: 70px;" aria-label="First name: activate to sort column descending"
                                        aria-sort="ascending">软件名称
                                    </th>
                                    <th class="sorting" tabindex="0"
                                        aria-controls="datatable-responsive" rowspan="1" colspan="1"
                                        style="width: 10px;"
                                        aria-label="Last name: activate to sort column ascending">
                                        版本号
                                    </th>
                                    <th class="sorting" tabindex="0"
                                        aria-controls="datatable-responsive" rowspan="1" colspan="1"
                                        style="width: 90px;"
                                        aria-label="Last name: activate to sort column ascending">
                                        版本大小(单位:M)
                                    </th>
                                    <th class="sorting" tabindex="0"
                                        aria-controls="datatable-responsive" rowspan="1" colspan="1"
                                        style="width: 50px;"
                                        aria-label="Last name: activate to sort column ascending">
                                        发布状态
                                    </th>
                                    <th class="sorting" tabindex="0"
                                        aria-controls="datatable-responsive" rowspan="1" colspan="1"
                                        style="width: 50px;"
                                        aria-label="Last name: activate to sort column ascending">
                                        APK文件下载
                                    </th>
                                    <th class="sorting" tabindex="0"
                                        aria-controls="datatable-responsive" rowspan="1" colspan="1"
                                        style="width: 50px;"
                                        aria-label="Last name: activate to sort column ascending">
                                        最新更新时间
                                    </th>
                                </tr>
                                </thead>
                                <tbody>
                                <c:forEach var="appVersion" items="${appVersions3}" varStatus="status">

                                    <tr role="row" class="odd">
                                        <td tabindex="0" class="sorting_1">${appVersion.softwareName}</td>
                                        <td>${appVersion.versionNo}</td>
                                        <td>${appVersion.versionSize }</td>
                                        <td>${appVersion.valueName }</td>
                                        <td>
                                            <a href="${appVersion.downloadLink }">${appVersion.apkFileName }</a>
                                        </td>
                                        <td>${appVersion.creationDate }</td>
                                    </tr>
                                </c:forEach>
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
                <div class="clearfix"></div>
                <div class="x_title">
                    <h2>修改最新版本信息</h2>
                    <ul class="nav navbar-right panel_toolbox">
                        <li><a class="collapse-link"><i class="fa fa-chevron-up"></i></a>
                        </li>
                    </ul>
                    <div class="clearfix"></div>
                </div>
                <div class="x_content" style="display: block;">
                    <br>
                    <form class="form-horizontal form-label-left"
                          action="${pageContext.request.contextPath}/eve/updataVersionmodify" method="post"
                          enctype="multipart/form-data">
                        <input type="hidden" name="id" id="id" value="${appVersionMap.id}">
                        <input type="hidden" name="modifyBy" id="appId" value="${user.id}">
                        <div class="item form-group">
                            <label class="control-label col-md-3 col-sm-3 col-xs-12" for="name">版本号 <span
                                    class="required">*</span>
                            </label>
                            <div class="col-md-6 col-sm-6 col-xs-12">
                                <input class="form-control col-md-7 col-xs-12" value="${appVersionMap.versionNo }"
                                       type="text" readonly="readonly" id="versionNo" name="versionNo">
                            </div>
                        </div>
                        <div class="item form-group">
                            <label class="control-label col-md-3 col-sm-3 col-xs-12" for="number">版本大小 <span
                                    class="required">*</span>
                            </label>
                            <div class="col-md-6 col-sm-6 col-xs-12">
                                <input type="number" id="versionSize" name="versionSize"
                                       value="${appVersionMap.versionSize }" required="required"
                                       data-validate-minmax="10,500" placeholder="请输入版本大小，单位为Mb"
                                       class="form-control col-md-7 col-xs-12">
                            </div>
                        </div>

                        <div class="item form-group">
                            <label class="control-label col-md-3 col-sm-3 col-xs-12" for="select">发布状态 <span
                                    class="required">*</span></label>
                            <div class="col-md-6 col-sm-6 col-xs-12">
                                <input type="hidden" name="publishStatus" id="publishStatus" value="3">预发布
                            </div>
                        </div>

                        <div class="item form-group">
                            <label class="control-label col-md-3 col-sm-3 col-xs-12" for="textarea">版本简介 <span
                                    class="required">*</span>
                            </label>
                            <div class="col-md-6 col-sm-6 col-xs-12">
              <textarea id="versionInfo" name="versionInfo" required="required"
                        placeholder="请输入本版本的相关信息，本信息作为该版本的详细信息进行版本介绍。" class="form-control col-md-7 col-xs-12">
                  ${appVersionMap.versionInfo }</textarea>
                            </div>
                        </div>
                        <div class="item form-group">
                            <label class="control-label col-md-3 col-sm-3 col-xs-12" for="name">apk文件 <span
                                    class="required">*</span>
                            </label>
                            <div class="col-md-6 col-sm-6 col-xs-12">
                                <input type="hidden" id="downloadLink" name="downloadLink"
                                       value="${appVersionMap.downloadLink}"/>
                                <input type="hidden" id="apkLocPath" name="apkLocPath"
                                       value="${appVersionMap.apkLocPath}"/>
                                <input type="hidden" id="apkFileName" name="apkFileName"
                                       value="${appVersionMap.apkFileName}"/>
                                <div id="uploadfile" style="display: none">
                                    <input id="attach" type="file" class="form-control col-md-7 col-xs-12"
                                           name="apkLocPath_File">
                                    <p><span style="color:red;font-weight: bold;">*注：1、大小不得超过500m.2、文件类型：apk</span></p>
                                </div>
                                <div id="apkFile"></div>
                                ${fileUploadError }
                            </div>
                        </div>
                        <div class="ln_solid"></div>
                        <div class="form-group">
                            <div class="col-md-6 col-md-offset-3">
                                <button id="send" type="submit" class="btn btn-success">保存</button>
                                <button type="button" class="btn btn-primary" id="back">返回</button>
                            </div>
                        </div>
                        <div class="clearfix"></div>
                        <br/><br/>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
<%@include file="common/footer.jsp" %>
<%--<script src="${pageContext.request.contextPath}/statics/localjs/appversionmodify.js"></script>--%>
<script src="${pageContext.request.contextPath}/statics/localjs/appinfoview.js"></script>


<script>
    $(function () {

        var att = $("#attach").val();

        console.log("asdasdasd------>>", att)
        $("#attach").change(function () {
            var files = $("#attach").val();

            var sum = files.lastIndexOf(".");

            files.substring(0, sum);

            var print = files.substring(sum + 1);//截取文件后缀

            var reg = /(?:apk)$/;

            if (reg.test(print)) {

                console.log("文件名为：", print);
            } else {
                alert("抱歉您上传的不是apk文件！请重新上传！")
                $("#attach").val('');
            }
        })
    })
</script>

<script>
    function delfile(id) {

        $.ajax({
            type: "post",//请求类型
            url: "/eve/delfile",//请求的url
            data: {id: id},//请求参数
            dataType: "json",//ajax接口（请求url）返回的数据类型
            success: function (data) {//data：返回数据（json对象）
                if (data.result == "success") {
                    alert("删除成功！");
                    $("#uploadfile").show();
                    $("#apkFile").html('');
                } else if (data.result == "failed") {
                    alert("删除失败！");
                }
            },
            error: function (data) {//当访问时候，404，500 等非200的错误状态码
                alert("请求错误！");
            }
        });
    }

    $(function () {
        //上传APK文件---------------------
        var downloadLink = $("#downloadLink").val();
        var id = $("#id").val();
        var apkFileName = $("#apkFileName").val();
        if (downloadLink == null || downloadLink == "") {
            $("#uploadfile").show();
        } else {
            $("#apkFile").append("<p>" + apkFileName +
                "&nbsp;&nbsp;<a href=\"" + downloadLink + "?m=" + Math.random() + "\" >下载</a> &nbsp;&nbsp;" +
                "<a href=\"javascript:;\" onclick=\"delfile('" + id + "');\">删除</a></p>");
        }
    });

</script>